package com.ztjava.common.service;

import java.util.Map;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
import com.ztjava.common.model.files.FilesInfo;
import com.ztjava.core.base.BaseService;
import com.ztjava.core.client.Client;

public class FilesService extends BaseService {
	/***
	 * 保存文件记录
	 * @param api
	 * @param ret
	 * @param user_id
	 */
	public void insertInfo(String type,Ret ret,Integer user_id){
		FilesInfo filesInfo = new FilesInfo();
		filesInfo.set("name", ret.getStr("name"));
		filesInfo.set("path", ret.getStr("filePath"));
		filesInfo.set("local", ret.getStr("localPath"));
		filesInfo.set("foler", ret.getStr("folerPath"));
		filesInfo.set("server", ret.getStr("server"));
		filesInfo.set("ext",  ret.getStr("ext"));
		filesInfo.set("size", ret.getInt("size"));
		filesInfo.set("type", type);
		filesInfo.set("create_user", user_id);
		filesInfo.save();
	}
	
	/*************
	 *Info分页
	**************/
	public Page<FilesInfo> getInfoPage(Client client,Map<String,String[]> paramMap){
		String[][] param = new String[][]{
			new String[]{"name",like,"name"},
			new String[]{"path",like,"path"}
						};
		Page<FilesInfo> pd = FilesInfo.dao.paginate(
				getParaToInt(paramMap, client.getPageNumber(), 1), 
				getParaToInt(paramMap,client.getPageSize(),20),
				"select *","from "+FilesInfo.tablename+" where 1=1 " 				
				+ whereSql(paramMap,param)
				+ orderby(client, paramMap),whereParam(paramMap, param));

		return pd;
	}

}
